<?php
session_start();

//to render shopping cart total and article count in each page
require("storescripts/checkout_script.php");
//require("mail.php");
//require("storescripts/create_pdf.php");
//$cartArticles = 0;
//$cartTotal = "Total: $0.00";
$customer = $_SESSION["customer"];
$sql = mysql_query("SELECT * FROM customers WHERE u_name='$customer';");
$row = mysql_fetch_array($sql);

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: LuvoFashion.com';
$customer_email = $row["email"];
$customer_name = $row["f_name"]."\n".$row["l_name"];;
$subject = "Your Luvo Fashion Invoice";
// The message
//$message = '<html><body><table><tr><td>hello</td></tr></table></body></html>';
$message = '<html><body>Dear '.$customer_name.', <br><br> Here is the Official Receipt with your purchases:<br><br><table border="1" cellpadding="6" cellspacing="0"><tr><th align="center" colspan="5">Official Receipt</th></tr><tr align="center"><td width="150" class="cartTable">Product</td><td width="300" class="cartTable">Product Description</td><td width="65" class="cartTable">Unit Price</td><td width="65" class="cartTable">Quantity</td><td width="65" class="cartTable">Total</td></tr>' .$cartOutput. '<tr><td colspan ="5"><div align="right">' .$cartTotal.'</div></td></tr></table></body></html>';

// In case any of our lines are larger than 70 characters, we should use wordwrap()
//$message = wordwrap($message, 70);

// Send
//mail($customer_email, $subject, $message, $headers);

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Payment</title>
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen" />

</head>

<body>
<!-- Shell -->
<div class="shell">
  <!-- Header -->
  <div id="header">
    <h1 id="logo"><a href="index.php">Luvo Fashion</a></h1>
    <!-- Cart -->
    <div id="cart"> <a href="cart.php" class="cart-link">Your Shopping Cart</a>
      <div class="cl">&nbsp;</div>
      <span>Articles: <strong><?php echo $cartArticles;?></strong></span> &nbsp;<span><strong><?php echo $cartTotal;?></strong></span>
	</div>
    <!-- End Cart -->
    <!-- Navigation -->
    <div id="navigation">
      <ul>
       	<li><a href="index.php">Home</a></li>
		<li><a href="gallery.php">Gallery</a></li>
	    <li><a href="about_us.php">About Us</a></li>
	    <li><a href="faq.php">FAQ</a></li>
	    <li><a href="contact.php">Contact</a></li>
		<li><a href="account.php">My Account</a></li>
      </ul>
    </div>
    <!-- End Navigation -->
  </div>
  <!-- End Header -->
  <!-- Main -->
  <div id="main">
   	<!-- Content -->
		<div style="margin:10px; text-align:left;">
		<br />
		<h2>Official Receipt</h2><br />
		<h3>A copy of the receipt has been sent to your email: <?php echo $customer_email; ?> </h3><br />
		
		<table border="1" cellpadding="6" cellspacing="0">
		  <tr align="center">
		    <td width="150" class="cartTable">Product</td>
		    <td width="300" class="cartTable">Product Description</td>
		    <td width="65" class="cartTable">Unit Price</td>
		    <td width="65" class="cartTable">Quantity</td>
		    <td width="65" class="cartTable">Total</td>
	      </tr>
			<?php echo $cartOutput; ?>
			<tr>
				<td colspan ="5">
					<div align="right"><?php echo $cartTotal; ?></div>
				</td>
			</tr>
		</table><br />
		<a href="storescripts/create_pdf.php" target="_blank"> [Print Receipt] </a>
	</div>
	<br />
	<br />

    <!-- End Content -->
    <!-- Sidebar -->
    <!-- End Sidebar -->
    <div class="cl">&nbsp;</div>
  </div>
  <!-- End Main -->
  <!-- Footer -->
  <?php include_once("template_footer.php"); ?>
  <!-- End Footer -->
</div>
<?php unset($_SESSION["cart_array"]);
$sql1 = mysql_query("UPDATE products SET original_quantity - quantity WHERE id='$item_id'");
$sql = mysql_query("UPDATE products SET original_quantity = quantity WHERE id='$item_id'");
?>
<!-- End Shell -->
</body>
</html>
